<script>
function isMobile() {
    return (/phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone|webOS|android/i.test(navigator.userAgent))
}
var _isMobile=isMobile();
_h=h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
console.log(_isMobile);
//if(sWidth>540){sWidth=540;}
var _rate=(sWidth/750);
if(h<_rate*1206){
  h=_rate*1206;
}
function setKe(cname, cvalue){
  var cname='h1'+cname;
    var d = new Date();
    d.setTime(d.getTime() + (90*24*60*60*1000));
    var expires = "expires="+ d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getke(cname) {
  var cname='h1'+cname;
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
         }
         if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
         }
     }
    return "";
}
function chinanum(num){
    var china = new Array('零','一','二','三','四','五','六','七','八','九');  
    var arr = new Array();
    var num=num+'';
    var english = num.split("")  
    for(var i=0;i<english.length;i++){
        arr[i] = china[english[i]];
    }
    if(2 == english.length){
        if('一' == arr[0]){
          if ('零' == arr[1]) {
              return '十';
          }
          return ('十'+arr[1]);
        }else{
          if ('零' == arr[1]) {
               return (arr[0]+'十');
          }
          return (arr[0]+'十'+arr[1]);
        }
    }else{
      return arr.join("")  
    }
}
Array.prototype.shuffle = function(){
    let array = this;
    let len = array.length;
    for (let i = len - 1; i > 0; i--) {
      let j = Math.floor(Math.random() * (i + 1));
      [array[i], array[j]] = [array[j], array[i]];
    }
}
var _uid='<?php echo $uid; ?>';

var _userData={};
var _curId=0;
var _uPhone='';
$(function(){
  $(".p1").show();
  $('.container, .page').width(sWidth).height(h);
  $('.p-b').height(_rate*1206);
  $('.p1-bm').width(_rate*480).height(_rate*164).css({"top":_rate*630, "left":_rate*140});
  
  $('#p2-name').width(_rate*368).height(_rate*76).css({"top":_rate*261, "left":_rate*278});
  $('#p2-phone').width(_rate*368).height(_rate*76).css({"top":_rate*388, "left":_rate*278});
  $('#p2-idcard').width(_rate*368).height(_rate*76).css({"top":_rate*527, "left":_rate*278});
  $('.p2-bm').width(_rate*480).height(_rate*164).css({"top":_rate*700, "left":_rate*140});
 
  $('.zhu-ok').width(_rate*480).height(_rate*164).css({"top":_rate*770, "left":_rate*130});

  $('.dan-b1').height(_rate*25).css({"top":_rate*88, "left":_rate*72});
  $('.dan-b1-y').width(_rate*586);
  $('.dan-b1-x').width(0);

  $('.yib-b1').height(_rate*14).css({"top":_rate*70, "left":_rate*78});
  $('.yib-b1-y').width(_rate*574);
  $('.yib-b1-x').width(0);
  $('.yib-abcd').css({"top":_rate*430});
  $('.yib-li').height(_rate*100).css({"line-height":_rate*55+'px','margin-bottom':_rate*6});
  $('.dx-li-ico').width(_rate*48).height(_rate*48).css({"top":_rate*6, "left":0});
  $('.yib-li span').css({"margin-left":_rate*66});
  $('.dx-dan').css({'margin-top':_rate*20});
  $('.dx-a, .dx-b, .dx-c, .dx-d, .pan-a, .pan-b').width(_rate*134);
  $('.dx-a').css({"left":_rate*20});
  $('.dx-b').css({"left":_rate*174});
  $('.dx-c').css({"left":_rate*325});
  $('.dx-d').css({"left":_rate*472});
  
  $('.up-btn').width(_rate*290).css({"top":_rate*1030, "left":_rate*80});
  $('.next-btn').width(_rate*290).css({"top":_rate*1030, "left":_rate*382});
  
  $('.tipless-t1, .tipchen-t1').css({"top":_rate*260});
  

   
  if(h >= _rate*1333){
    var _cha=h - _rate*1300;
    if(_cha < 0){_cha=0;}
    $('.thebg').css({"top":_cha/2}); 
  }

  var _shuffle150Cookie=getke('sz_shuffle150Cookie');
  var _userIdCookie=getke('sz_userId');
  var _userPhoneCookie=getke('sz_phone');
   var _userCurStepCookie=getke('sz_userCurStepA'); //当前步骤
   var _userCountEndTime=getke('sz_endTime');
  if (typeof(_userIdCookie) != "undefined" && '' != _userIdCookie) {
    _uid=_userIdCookie;
  }
  if (typeof(_userPhoneCookie) != "undefined" &&'' != _userPhoneCookie) {
   _uPhone=_userPhoneCookie;
  }

  if('' == _shuffle150Cookie){
      var _shuffle150=[];
      for(var i=1;i<=150;i++){
        _shuffle150.push(i);
      }
      _shuffle150.shuffle();
      setKe('sz_shuffle150Cookie', _shuffle150);
  }else{
     var _shuffle150=_shuffle150Cookie.split(",");
  }
if(typeof(_shuffle150Cookie) != "undefined" && '' != _shuffle150Cookie && '' != _userPhoneCookie && '' != _userIdCookie){  //记忆

   if('y1' == _userCurStepCookie){

      var _tmDataStoreCookie=getke('sz_tmData');
      var _tmKeyStoreCookie=getke('sz_tmKey');

      if("" != _tmDataStoreCookie){
        var _tmpTmData=_tmDataStoreCookie.split(",");
        var _tmpTmKey=_tmKeyStoreCookie.split(",");
        for(var _i=0;_i<_tmpTmData.length;_i++){
           _userData[_tmpTmKey[_i]]=_tmpTmData[_i];
           _curId++;
        }
      }


    var _showId=_shuffle150[_curId];
     $(".dan-title").html("第"+chinanum((_curId+1))+"题（"+(_curId+1)+"/150）");
     $(".yib-bt, .yib-abcd").hide();
     $(".yb1-bt"+_showId+", .yb1-t"+_showId).show();
      
     for(var _i=0;_i<_curId;_i++){
        _showId=_shuffle150[_i];
        if(typeof(_userData[_showId]) != "undefined"){
           $(".yb1-t"+_showId+" .dx-"+_userData[_showId]+"1").attr("src","<?php echo $url; ?>/img/r.png");
           $(".yb1-t"+_showId+" .dx-"+_userData[_showId]+"2").attr("src","<?php echo $url; ?>/img/"+_userData[_showId]+"2.png");
        }
      }

     $(".p1").hide();
     $(".dan").show();
     _startCountTime();

   }
   if('end' == _userCurStepCookie){
      $(".tipchen").show();
   }
}
function _restartCookie(){
  
}

var end;
function _startCountTime(){
    var endDate = new Date();
    var min=endDate.getMinutes();
    endDate.setMinutes(min+15);
    end = endDate.getTime();
    if (typeof(_userCountEndTime) != "undefined" && '' != _userCountEndTime) {
        var date = new Date();  
        var now = date.getTime();
        if ((_userCountEndTime-now) >= 92000){
            end=_userCountEndTime;
        }
    }
    countTime();
    setKe('sz_endTime', end);
  }
  var _zongwidth=_rate*586;
  var _zongTime=60*15*1000;
  function countTime(){
    var date = new Date();  
    var now = date.getTime();
    var leftTime = end-now; 
    var m,s; 
    if (leftTime >= 0){
      m = Math.floor(leftTime/1000/60%60);
      s = Math.floor(leftTime/1000%60);
      var _tmpS=':'+s;
      if(s<10){
        _tmpS=':0'+s;
      }
      //console.log(leftTime);
      var _percent=1 - leftTime/_zongTime + 0.02;
      if(_percent>1){_percent=1;}
      
      $(".dan-b1-x").width(_percent*_zongwidth);
      

      $(".dan-time").html(m + _tmpS );
      setTimeout(countTime,1000); 
    }else{
      $(".dan-time").html("00:00");
      _tmTimeId=0;
      $(".tipless").show();
      console.log('end');
    }
  }


   $(".p2-bm").click(function(){
     var _name=$("#p2-name").val();
     var _phone=$("#p2-phone").val();
     var _idcard=$("#p2-idcard").val();
 
     if('' == _name){
         _popMsg("请填写姓名");
           return;  
     }
     if('' == _phone){
         _popMsg("请填写本人手机号码");
           return;  
     }
     if(_phone.length < 6){
        _popMsg("请填写可联系的真实手机号码");
        return;  
     }
     if(_phone.length != 11){
        _popMsg("请填写11位的手机号码");
        return;  
     }
     if('' == _idcard){
         _popMsg("请填写本人身份证号码");
         return; 
     }
     if(_idcard.length < 4){
        _popMsg("请填写真实的身份证号码");
        return;  
     }

    $.post("./api/?c=setu", {uid:_uid,n:_name,ph:_phone,idc:_idcard}, function(data){
          if('y' == data.s){
               _uPhone=_phone;
              setKe('sz_phone', _phone); 
              setKe('sz_userId', _uid);
              $(".p2").hide();
              $(".zhu").show();
          }
    }, "json");

  });


  function _popMsg(msg){
    $(".weui-msg").html(msg);
        $(".js_dialog").show();
  }   
  $(".weui-btn").click(function(){
        $(".js_dialog").hide();
  });

  $('.zhu-ok').click(function(){
    _popMsg("活动已结束");
    return;
    $.post("./api/?c=gettime", {i:1}, function(data){
          if('n' == data.s){
             _popMsg("考试时间未到，20点正式考试");
             return;  
          }else{
             $(".p1, .zhu").hide();
             $(".dan").show();
            var _showId=_shuffle150[_curId];
             $(".dan-title").html("第"+chinanum((_curId+1))+"题（"+(_curId+1)+"/100）");
             $(".yib-bt, .yib-abcd").hide();
             $(".yb1-bt"+_showId+", .yb1-t"+_showId).show();
            _startCountTime();
          }
    }, "json");

    

  });

 
  $('.next-btn').click(function(){
        _curId++;
        if(_curId > 148){
          console.log(111);
              $(".next-btn-t").attr("src","<?php echo $url; ?>/img/next-btn2.png");
              $(".next-btn-h").attr("src","<?php echo $url; ?>/img/r-btn.png");  
              //return;
        }
        if(_curId > 149){
          $.post("./api/?c=setdan", {yi:_userData,op:_uid,phone:_uPhone}, function(data){
               $(".tipchen").show();
                setKe('sz_userCurStepA', 'end');  
          }, "json");
           console.log('提交+end'); 
           return;
        }
        
        $(".yib-bt, .yib-abcd").hide();
        $(".dan-title").html("第"+chinanum((_curId+1))+"题（"+(_curId+1)+"/150）");
        var _showId=_shuffle150[_curId];
        $(".yb1-bt"+_showId+", .yb1-t"+_showId).show();
              
        $(".next-btn-h").attr("src","<?php echo $url; ?>/img/r-btn.png");
        window.setTimeout(function(){
          $(".next-btn-h").attr("src","<?php echo $url; ?>/img/h-btn.png");
        }, 200);
         
   });

  $('.up-btn').click(function(){
      if(0 == _curId){return;}
      if(_curId < 0){return;}
       _curId--;
      $(".next-btn-t").attr("src","<?php echo $url; ?>/img/next-btn.png");
      $(".up-btn-h").attr("src","<?php echo $url; ?>/img/r-btn.png");
       $(".yib-bt, .yib-abcd").hide();
        $(".dan-title").html("第"+chinanum((_curId+1))+"题（"+(_curId+1)+"/150）");
        var _showId=_shuffle150[_curId];
        $(".yb1-bt"+_showId+", .yb1-t"+_showId).show();
        
       $(".up-btn-h").attr("src","<?php echo $url; ?>/img/r-btn.png");
       window.setTimeout(function(){
          $(".up-btn-h").attr("src","<?php echo $url; ?>/img/h-btn.png");
        }, 200);


   });

  function _resetABCD(_type, _showId){
      _userData[_showId]=_type;
       var _tmData=[];
       var _tmKey=[];  
       $.each(_userData,function(key,value) {
            _tmKey.push(key);
            _tmData.push(value);
        }); 
        setKe('sz_tmData', _tmData);
        setKe('sz_tmKey', _tmKey);
        setKe('sz_userCurStepA', 'y1');
      
      $(".yb1-t"+_showId+" .dx-a1, .yb1-t"+_showId+" .dx-b1").attr("src","<?php echo $url; ?>/img/h.png");
      $(".yb1-t"+_showId+" .dx-c1, .yb1-t"+_showId+" .dx-d1").attr("src","<?php echo $url; ?>/img/h.png");

      $(".yb1-t"+_showId+" .dx-a2").attr("src","<?php echo $url; ?>/img/a.png");
      $(".yb1-t"+_showId+" .dx-b2").attr("src","<?php echo $url; ?>/img/b.png");
      $(".yb1-t"+_showId+" .dx-c2").attr("src","<?php echo $url; ?>/img/c.png");
      $(".yb1-t"+_showId+" .dx-d2").attr("src","<?php echo $url; ?>/img/d.png");
      $(".yb1-t"+_showId+" .dx-"+_type+"1").attr("src","<?php echo $url; ?>/img/r.png");
      $(".yb1-t"+_showId+" .dx-"+_type+"2").attr("src","<?php echo $url; ?>/img/"+_type+"2.png");
 }

  $(".yb1-abcd .dx-a").click(function(){
       _showId=_shuffle150[_curId];
       _resetABCD('a', _showId);
   });
   $(".yb1-abcd .dx-b").click(function(){
       _showId=_shuffle150[_curId];
       _resetABCD('b', _showId);
   });
   $(".yb1-abcd .dx-c").click(function(){
       _showId=_shuffle150[_curId];
       _resetABCD('c', _showId);
   });
   $(".yb1-abcd .dx-d").click(function(){
       _showId=_shuffle150[_curId];
       _resetABCD('d', _showId);
   });

   $('.tipless-t1').click(function(){
         $.post("./api/?c=setdan", {yi:_userData,op:_uid,phone:_uPhone}, function(data){
               $(".tipchen").show();
               setKe('sz_userCurStepA', 'end');  
          }, "json");
   });

   $('.tipchen-t1').click(function(){
      _popMsg("考试已完成");
         
   });

   $('.p1-bm').click(function(){
    _popMsg("活动已结束");
    return;
      if (typeof(_userIdCookie) != "undefined" && '' != _userIdCookie && '' != _userPhoneCookie) {
         $(".zhu").show();
      }else{
         $(".p2").show();
      }
   });

   
 
  
    
});
</script>